<!--************************************************************************************************-->
<!-- < mainPage.php >                                                                               -->
<!-- Copyright (c) 2012-2013 San Yat-sun University School of Software                              -->
<!-- Founder & Modifier: Xiaoxin Mo                                                                 -->
<!-- Stu : 10389159                                                                                 -->
<!-- Date: 2012-12-23                                                                               -->
<!-- Destription : 通过url访问论文页面                                                           -->
<!--                                                                                                -->
<!-- Version : 2.1                                                                                  -->
<!--************************************************************************************************-->

<!DOCTYPE html>
<?php
	session_start();
	//include_once("header.php");
	//include_once("bottom.php");
	include_once("../manager/ThesisManager.php");
	include_once("../manager/LabelManager.php");
	include_once("../manager/DescriptionManager.php");
	include_once("../db/Thesis.php");
	include_once("../db/Label.php");
	include_once("../db/Description.php");
?>
<html lang="zh-hk">
	<?php

	if( isset($_POST['thesisname'])) 
	{
		$thesisname = $_POST['thesisname'];
		$authorName = $_POST['authorname'];
		$authorBrief = $_POST['authorbrief'];
		$uploaderID = $_SESSION['currentID'];
		$pages = $_POST['pages'];
		$content = $_POST['content'];
		
		/*Edit BY Tianjiao Li AT 2013-1-2 17:18*/
		$labels = $_POST['labels'];
		$tableName = "Labels";
		
		$list_of_labels = explode(" ", $labels);
		//echo $list_of_labels;
		
		foreach ($list_of_labels as $label_content) 
		{
			$labelManager = new LabelManager();
			if(!$labelManager->exist($label_content))
			{
				$array = array('Content'=>$label_content);
				LabelManager::getInstance()->insert($array);
			}
		}
		/*Edit BY Tianjiao Li*/
		
		$array = array('Thesisname'=>$thesisname, 'AuthorName'=>$authorName, 'AuthorBrief'=>$authorBrief, 'UploaderID'=>$uploaderID, 'Pages'=>$pages, 'Content'=>$content);
		
		ThesisManager::getInstance()->insert($array);
	
		/*Edit BY Tianjiao Li AT 2013-1-2 17:18*/
		foreach ($list_of_labels as $label_content) 
		{
			$array = array('content'=>$label_content, 'Thesisname'=>$thesisname);
			DescriptionManager::getInstance()->insert($array);
		}
		/*Edit BY Tianjiao Li*/
		// 获得当前上传论文，用于跳转到论文页面
		$_SESSION['currentThesis'] = $thesisname;
	}
	?>
	
	<head>
		<title>TINY bOOk</title>
		<meta http-equiv="Content-Type" content="text/html charset=UTF-8">
		<meta name="contentType" value="text/html  charset=GBK">
		<meta name="description" content="在这里你可以看到最新发布的书籍，和好友共享对某本书的评论和笔记">
		<meta http-equiv="imagetoolbar" content="no">
		<meta name="viewport" content="width=1036">
		
		<link rel="stylesheet" type="text/css" href="../css/result.css"/>
		<link rel="shortcut icon" href="images/shortcut.jpg"/>
		<meta http-equiv="refresh" content="1; url=thesisPage.php?thesis_name=<?=$thesisname?>">
	</head>	
		
	<body>
		<div id="title">
			<h1>TINY bOOk</h1>
		</div>

		<div id="hasRegister">
			<p>已成功上传论文，跳转到论文页面</a></p>
		</div>
	</body>
</html>